package cn.javazd.tcp;

import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class TcpServer {

	public static void main(String[] args) {
		try {
			ServerSocket serverSocket = new ServerSocket(9090);
			Socket scoket = serverSocket.accept();

			InputStream in = scoket.getInputStream();
			byte[] buf = new byte[1024];
			int length = in.read(buf);
			System.out.println("server receive data: " + new String(buf, 0, length));

			OutputStream out = scoket.getOutputStream();
			out.write("hello client!!!".getBytes());

			serverSocket.close();

		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}
